package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(83)
public class ShanshuoGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://114.66.45.45:801/gmsss/gzs.php";
    public static final String DELITEM = "http://114.66.45.45:801/gmss/ht/api.php";

    /**
     * qu:1
     * sqm:diyao88
     * usr:m66666
     * pay:111221
     * type:7
     *
     * @param item
     * @return
     */
    @GongnengMethod(8301)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("sqm", "diyao88");
        params.add("type", item.itemId);
        params.add("qu", "1");

        params.add("usr", item.uid);
        params.add("7".equals(item.itemId) ? "pay" : "gb", item.number);
        return RestTemplateUtil.sendPostForm(URL, params);
    }
    @GongnengMethod(8302)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("sqm", "diyao88");
        params.add("type", "8");
        params.add("qu", "1");

        params.add("usr", item.uid);
        params.add("num", item.number);
        params.add("item", item.itemId);

        return RestTemplateUtil.sendPostForm(URL, params);
    }


    /**
     * qu=1&usr=m66666&pay=&bao=0&num=1122&item=10001&gnxz=4&bid=0&starts=0&lev=
     * @param item
     * @return
     */
    @GongnengMethod(8303)
    public String delItem(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("gnxz", "4");
        params.add("qu", "1");

        params.add("usr", item.uid);
        params.add("num", item.number);
        params.add("item", item.itemId);

        return RestTemplateUtil.sendPostForm(DELITEM, params);
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "m66666";
        item.number = "992";
        item.itemId = "10001";
        System.out.println(new ShanshuoGameStrategy().delItem(item));
    }
}

